import axios from "axios";
import {RVo} from "./Rvo.ts";
import {RouteDef} from "../model/RouteDef.ts";
//import { loadEnv } from "vite";


const BASE_URL = () => {
    return import.meta.env.VITE_BASE_URL + '/actuator'
}


export function getRouteFeatureDefinitions() {
    return axios.get<RVo<RouteDef[]>>( `${BASE_URL()}/routeFeature/definitions` )
}

export function getRouteFeatureDefinition( id : string ) {
    return axios.get<RVo<RouteDef>>( `${BASE_URL()}/routeFeature/definitions/${id}` )
}


export function getRouteStableDefinitions() {
    return axios.get<RVo<RouteDef[]>>( `${BASE_URL()}/routeStable/definitions` )
}

export function getRouteStableDefinition( id : string ) {
    return axios.get<RVo<RouteDef>>( `${BASE_URL()}/routeStable/definition${id}` )
}

export function addOrUpdateRouteFeatureDefinition(routeDef : RouteDef ) {
    return axios.post<RVo<boolean>>( `${BASE_URL()}/routeFeature/definition/${routeDef.id}` , routeDef )
}


export function removeRouteFeatureDefinition( id : string ) {
    return axios.delete<RVo<RouteDef>>( `${BASE_URL()}/routeFeature/definition/${id}` )
}

export function commit( id : string  ) {
    return axios.post<RVo<boolean>>( `${BASE_URL()}/routeFeature/definition/${id}/commit` )
}

export function commitAll() {
    return axios.post<RVo<boolean>>( `${BASE_URL()}/routeFeature/definitions/commit` )
}

export function rollbackAll() {
    return axios.post<RVo<boolean>>( `${BASE_URL()}/routeFeature/definitions/rollback` )
}

export function rollback( id : string ) {
    return axios.post<RVo<boolean>>( `${BASE_URL()}/routeFeature/definition/${id}/commit` )
}